.PHONY: help dev build test clean install-deps generate

# Default target
help:
	@echo "Available targets:"
	@echo "  dev          - Start development environment"
	@echo "  build        - Build all components"
	@echo "  test         - Run all tests"
	@echo "  clean        - Clean build artifacts"
	@echo "  install-deps - Install all dependencies"
	@echo "  generate     - Generate code from OpenAPI specs"

# Development environment
dev:
	docker-compose up -d
	@echo "Development environment started"
	@echo "Backend: http://localhost:8080"
	@echo "Frontend: http://localhost:3000"

# Install dependencies
install-deps:
	@echo "Installing Go dependencies..."
	cd backend && go mod download
	@echo "Installing Node.js dependencies..."
	cd frontend && npm install

# Generate code from OpenAPI specs
generate:
	@echo "Generating Go server code..."
	cd backend && go generate ./...
	@echo "Generating TypeScript client code..."
	cd frontend && npm run generate

# Build all components
build: generate
	@echo "Building backend..."
	cd backend && go build -o bin/car-server ./cmd/server
	@echo "Building frontend..."
	cd frontend && npm run build

# Run tests
test:
	@echo "Running backend tests..."
	cd backend && go test ./...
	@echo "Running frontend tests..."
	cd frontend && npm run test

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	rm -rf backend/bin
	rm -rf frontend/dist
	rm -rf backend/generated
	rm -rf frontend/src/generated

# Docker build
docker-build:
	docker build -t car-backend -f backend/Dockerfile .
	docker build -t car-frontend -f frontend/Dockerfile .

# Production deployment
deploy: build docker-build
	docker-compose -f docker-compose.prod.yml up -d